
import 'package:shortmovieapp/data/viewData.dart';
import 'package:shortmovieapp/myController/RequestServerController.dart';
import 'package:shortmovieapp/myController/appController.dart';
import 'package:shortmovieapp/myPages/movieEditPage.dart';
import 'package:shortmovieapp/myPages/myVideoPage.dart';
import 'package:shortmovieapp/myPages/createMoviePage.dart';
import 'package:shortmovieapp/myPages/recommendedPage.dart';
import 'package:shortmovieapp/style/style.dart';
import 'package:shortmovieapp/myPages/myHomePage.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:shortmovieapp/myPages/mySearchPage.dart';
import 'dart:io';

void main() {
  /// 自定义报错页面
  if (kReleaseMode) {
    ErrorWidget.builder = (FlutterErrorDetails flutterErrorDetails) {
      debugPrint(flutterErrorDetails.toString());
      return const Material(
        child: Center(
            child: Text(
          "发生了没有处理的错误\n请通知开发者",
          textAlign: TextAlign.center,
        )),
      );
    };
  }
  HttpOverrides.global = MyHttpOverrides();
  runApp(MyApp());
}


 class MyHttpOverrides extends HttpOverrides{
  @override
  HttpClient createHttpClient(SecurityContext? context){
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
  }
}
class MyApp extends StatelessWidget {

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {

   
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      //title: 'Flutter Tiktok',
      theme: ThemeData(
        brightness: Brightness.dark,
        hintColor: Colors.white,
        //accentColor: Colors.white,
        primaryColor: ColorPlate.orange,
        //primaryColorBrightness: Brightness.dark,
        scaffoldBackgroundColor: ColorPlate.back2,
        dialogBackgroundColor: ColorPlate.back2,
        //accentColorBrightness: Brightness.light,
        textTheme: const TextTheme(
          bodyText1: StandardTextStyle.normal,
        ),
      ),
      home: const myHomePage(),// HomePage(),
      initialRoute: '/',
      onGenerateRoute: getRouteSetting,
    );

    
  }

 Map routes = {
      '/': (context) => const myHomePage(),
      MyPageRoute.seach: (context) => const mySearchPage(),
      MyPageRoute.video:(context,{arguments}) =>  myVideoPage(arguments: arguments),
      MyPageRoute.createMovie:(context) => const createMoviePage(),
      MyPageRoute.movieEdit:(context,{arguments}) => movieEidtPage.movieEditPage(data: arguments),
      // '/form': (context, {arguments}) => FormPage(arguments: arguments),
    };

  Route? getRouteSetting(RouteSettings settings){
  final String? name = settings.name;
          final Function? pageContentBuilder = routes[name];
          if (pageContentBuilder != null) {
            if (settings.arguments != null) {
              final Route route = MaterialPageRoute(
                  builder: (context) =>
                      pageContentBuilder(context, arguments: settings.arguments));
              return route;
            } else {
              final Route route = MaterialPageRoute(
                  builder: (context) => pageContentBuilder(context));
              return route;
            }
          }
          return null;
  }

}
